import React from "react";
import {connect} from "react-redux";
import "../../static/contact.css"
import {clearData, saveFormData} from "../../store/user/action";
class contact extends React.Component {
    constructor(props){
        super(props)
        console.log(this.props)
        this.handleClick = this.handleClick.bind(this);
        this.handleChange = this.handleChange.bind(this);
        this.state={
            name:""
        }
    }
    componentWillMount() {

    }
    handleChange(e) {
        this.setState({
            name:e.target.value
        })
    }
    handleClick() {
        if(!this.state.name){
            alert("请输入用户名")
            return;
        }
        this.props.saveFormData({
            name:this.state.name
        })
        alert("登录成功")
        console.log(this.props)
        this.props.history.push("/stuff")
    }

    render() {
        return (
            <div className={"min-height"}>
                <input type="text" onChange={this.handleChange} value={this.state.name}/>
                <div onClick={this.handleClick}>
                    <span>提交</span>
                </div>

            </div>
        );
    }
}

export default  connect(store => ({
    userData:store.userData
}),{saveFormData, clearData})(contact);

